<template>
	<view class="student">
		<view class="header">
			<view class="search">
				<u-search placeholder="搜索学员昵称" :show-action="false" shape="square" v-model="query.search" @change="changeSearch"></u-search>
			</view>
			<view class="tab">
				<view v-for="(item,index) in tabList" :key="index" class="tabIndex" @click="changeIndex(index)">
					<view :class="activeIndex == index ?'tabsize1':'tabsize2'">
						{{item}}
					</view>
					<view class="active">
						<view class="empty" v-if="activeIndex == index">
			
						</view>
					</view>
				</view>
			</view>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="scrolltolower">
			<view class="comlumn_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item" @click="routecourse(item, index)">
					<view class="img">
						<image :src="item.avatar" mode="" class="avater"  @click.stop="$PREVIEW_IMAGE(item.avatar)"></image>
						<image
							:src="!item.gender ?$IMG_URL('/static/mannager/girl.png'):$IMG_URL('/static/mannager/boy.png')"
							mode="aspectFill" class="sex"></image>
					</view>
					<view class="right">
						<view class="title">
							{{item.nickname}}
						</view>
						<view class="bottom" v-if="item.is_course">
							<view class="size">
								{{item.course_str}}
							</view>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999999" size="14"></u-icon>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="!activeIndex ?'学员':activeIndex == 1 ?'进行中学员':'已完成学员'"></empty>
		</scroll-view>
	</view>
</template>

<script>
	import{
		memberDetailsList
	} from '@/api/coach.js'
	import empty from './components/empty.vue'
	export default{
		components:{
			empty
		},
		data(){
			return{
				query:{
					search:'',
					form:'',
					page:1
				},
				// 导航
				tabList: [
					'全部',
					'进行中',
					'已完成',
				],
				activeIndex: 0,
				list: [
				],
				status: 'loadmore', //当前状态
			}
		},
		onLoad() {
			this.getmemberDetailsList()
		},
		methods:{
			changeSearch(){
				this.list = []
				this.query.page = 1
				this.getmemberDetailsList()
			},
			scrolltolower(){
				this.query.page++
				this.getmemberDetailsList()
			},
			getmemberDetailsList(){
				memberDetailsList(this.query).then(({data:res})=>{
					console.log('res', res);
					if (res.code == 1) {
						const list = res.data.coupon_list
						this.tabList[0] = '全部(' + res.data.all_num + ')'
						this.tabList[1] = '进行中(' + res.data.unfinished_num + ')'
						this.tabList[2] = '已完成(' + res.data.finish_num + ')'
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}
						console.log('list', this.list);
					}
				})
			},
			changeIndex(index) {
				if(this.activeIndex != index){
					if (!index) {
						this.list = []
						this.query.page = 1
						this.query.form = 'all'
						this.getmemberDetailsList()
					} else if(index == 1){
						this.list = []
						this.query.page = 1
						this.query.form = 'unfinished'
						this.getmemberDetailsList()
					}else{
						this.list = []
						this.query.page = 1
						this.query.form = 'finish'
						this.getmemberDetailsList()
					}
					this.activeIndex = index
				}
			},
			routecourse(item, index){
				uni.navigateTo({
					url:'course?user_id=' + item.user_id
				})
			}
		}
	}
</script>

<style lang="scss" >
	page{
		background: #e9e9e9;
	}
	.student{
		display: flex;
		flex-direction: column;
		align-items: center;
		.header{
			width: 100%;
			height: 178rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(199,205,179,0.15); 
			display: flex;
			flex-direction: column;
			align-items: center;
			.search{
				width: 100%;
				padding: 24rpx;
			}
			.tab {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-around;
				background: #ffffff;
			
				.tabIndex {
					display: flex;
					flex-direction: column;
					align-items: center;
			
					.tabsize1 {
						height: 44rpx;
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC-Heavy;
						font-weight: 800;
						text-align: center;
						color: #73F0EA;
						letter-spacing: 0.7rpx;
			
					}
			
					.tabsize2 {
						height: 44rpx;
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: center;
						color: #666666;
						letter-spacing: 0.7rpx;
			
					}
			
					.active {
						margin-top: 12rpx;
						width: 44rpx;
						height: 8rpx;
			
						.empty {
							width: 100%;
							height: 100%;
							background: #73F0EA;
							border: 2rpx solid rgba(0, 0, 0, 0.00);
							border-radius: 2rpx;
						}
					}
				}
			}
			
		}
		.scroll-Y {
			width: 100%;
			height: 85vh;
			.comlumn_box {
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 24rpx;
		
				.Item {
					width: 702rpx;
					height: 128rpx;
					background: #ffffff;
					border-radius: 16rpx;
					padding: 0 24rpx;
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-bottom: 20rpx;
		
					.img {
						width: 80rpx;
						height: 80rpx;
						background: #f6f6f6;
						border-radius: 50%;
						position: relative;
						margin-right: 20rpx;
		
						.avater {
							width: 100%;
							height: 100%;
						}
		
						.sex {
							position: absolute;
							right: 0;
							bottom: 0;
							width: 26rpx;
							height: 26rpx;
						}
					}
		
					.right {
						display: flex;
						flex-direction: column;
						flex: 1;
		
						.title {
							font-size: 32rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: left;
							color: #333333;
						}
						.bottom{
							display: flex;
							flex-direction: row;
							align-items: center;
							.size{
								font-size: 24rpx;
								font-family: PingFang SC, PingFang SC-Regular;
								font-weight: 400;
								text-align: left;
								color: #000000;
							}
							.size1{
								font-size: 24rpx;
								font-family: PingFang SC, PingFang SC-Regular;
								font-weight: 400;
								text-align: left;
								color: #999999;
							}
							.gang{
								width: 0rpx;
								height: 24rpx;
								border: 1rpx solid #000000;
								margin: 0 10rpx;
							}
						}
					}
				}
			}
		}
	}
</style>